package com.feifan.web.controller.oa;

import com.feifan.oa.service.WebSocketServer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@Controller
public class MyWebSocket {

    @RequestMapping("/socket/{cid}")
    public ModelAndView socket(@PathVariable("cid") String cid) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("cid", cid);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/socket/push/{cid}")
    public String pushToWeb(@PathVariable String cid, String message) {
        try {
            WebSocketServer.sendInfo(message, cid);
        } catch (IOException e) {
            return "推送失败";
        }
        return "发送成功";
    }



}
